package com.maolong.subscribe;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class SubscribeConsumer {
    private static final String QUEUE= "publish_queue1";
    private static final String QUEUE2= "publish_queue2";
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("182.92.151.172");
        factory.setUsername("maolong");
        factory.setPassword("123456");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE, false, false, false, null);
        channel.queueDeclare(QUEUE2, false, false, false, null);

        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String message = new String(delivery.getBody(), "UTF-8");
            System.out.println(" [x] Received '" + message + "'");
        };

        channel.basicConsume(QUEUE, true, deliverCallback, consumerTag -> { });
        channel.basicConsume(QUEUE2, true, deliverCallback, consumerTag -> { });


    }
}
